/*
 * @Descripttion: 
 * @version: 
 * @Author: guangyunl
 * @Date: 2024-01-19 22:31:53
 * @LastEditors: guangyunl
 * @LastEditTime: 2024-03-20 23:08:15
 */
/* indent size: 2 */

module.exports = app => {
    const DataTypes = app.Sequelize;
  
    const Classes = app.model.define('classes', {
      id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        comment: '分类ID'
      },
      title:{
        type: DataTypes.STRING,
        allowNull: true,
        comment: '分类标题'
      },
      sort: {
        type: DataTypes.INTEGER,
        allowNull: true,
        defaultValue: 0,
        comment: '分类排序'
      },
      cid: {
        type: DataTypes.INTEGER,
        allowNull: true,
        defaultValue: 0,
        comment: '归属分类【二级分类】'
      },
      img: {
        type: DataTypes.STRING,
        allowNull: true,
        comment: '分类图标【二级分类配置】'
      },
      createdAt: {
        type: DataTypes.DATE,
        allowNull: true,
        comment: '创建时间'
      },
      updatedAt: {
        type: DataTypes.DATE,
        allowNull: true,
        comment: '更新时间'
      }
    }, {
      tableName: 'classes'
    });
  
    Classes.associate = function() {
  
      // Classes.belongsToMany(models.Products, {
      //   through: 'Products_classes',
      //   foreignKey: 'cid',
      //   otherKey: 'pid'
      // });

      // app.model.Classes.belongsToMany(app.model.Products,
      //   {
      //     through: app.model.ProductsClasses,
      //     foreignKey: "cid",
      //     otherKey: "pid"
      //   })
  
    }
  
    return Classes;
  };
  